package com.easy.frame.servers.sys.controller.process;

import com.easy.frame.base.basic.ServiceResponse;
import com.easy.frame.base.service.base.BaseController;
import com.easy.frame.common.process.core.factory.AbstractProcessFactory;
import com.easy.frame.common.process.core.service.ProcessBizService;
import com.easy.frame.common.process.entity.define.vo.ProcessDefineVO;
import com.easy.frame.common.process.entity.template.Process;
import com.easy.frame.common.process.entity.template.dto.ProcessAddDetailDTO;
import com.easy.frame.common.process.util.ProcessBizHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 流程相关接口类
 *
 * @author zzf
 * @date 8:38 2021/4/7
 */
@Slf4j
@Validated
@Api(tags = "流程相关接口")
@RestController
@RequestMapping("/process")
public class ProcessController extends BaseController {

    private AbstractProcessFactory factory;

    @Resource
    private ProcessBizService processBizService;

    @ApiOperation("获取流程定义")
    @GetMapping("/define")
    public ServiceResponse<List<ProcessDefineVO>> getProcessDefine() {
        List<ProcessDefineVO> result = ProcessBizHelper.getProcessDefineVOList(factory.getProcessDefineMap());
        return success(result);
    }

    @PostMapping
    public ServiceResponse<Process> addProcess(@Valid @RequestBody ProcessAddDetailDTO processAddDTO) {
        return success(processBizService.add(processAddDTO));
    }
}

